import React from 'react';
import {connect} from 'dva';
import { Spin } from 'antd';
var QRCode = require('qrcode.react');
@connect(({ products, loading }) => ({
  products,
  submitting: loading.effects['products/cuitao'],
}))
class Products extends React.Component {
  constructor(props){
    super(props);
    this.state={
      falg:true
    }
    this.eg=this.eg.bind(this);
    this.Oflag=this.Oflag.bind(this)
  }

  eg(cont) {
    // console.log(num);
    this.props.dispatch({
      type:"products/add",       //num代表数据模型，add代表方法。这里可以通过payload来传递参数。
      payload:{keyStr:'adsefrdj'},          
    })
  }
  Oflag(){
    this.setState({
      falg:false
    })
  }
  componentDidMount(){

    setTimeout(this.Oflag,3000)
  }
  render() {
    // const { dispatch, count } = this.props;
    
    return (
      <div>
           <div
            onClick={()=>{
                this.eg('我是修改的书具')
            }}
          >
                {this.props.haha}+'--------------'
          </div>
          <QRCode 
          size={200}
          fgColor={'red'}
          value="http://facebook.github.io/react/" />,
          <div style={{width:'100%',textAlign:'center',display:this.state.falg?'block':'none'}}>
          <Spin spinning={this.state.falg} />
          </div>
         
      </div>
     
    );
  }
}

function mapStateToProps(state) {
    // console.log(state,'获取的redux')
  return { haha: state.products};
} // 获取state

export default connect(mapStateToProps)(Products);